<template>
    <div id="feedback">
        <div class="dangerBtn">
            <yd-cell-group title="">
                <yd-cell-item>
                    <span slot="left">标题：</span>
                    <yd-input slot="right" required :show-required-icon='false' v-model="ifTitle" placeholder="请输入反馈标题"></yd-input>
                </yd-cell-item>
                <yd-cell-item>
                    <span slot="left">称呼：</span>
                    <yd-input slot="right" required :show-required-icon='false' v-model="ifMember" placeholder="请输入反馈者称呼"></yd-input>
                </yd-cell-item>
                <yd-cell-item>
                    <span slot="left">邮箱：</span>
                    <yd-input slot="right" ref="emailName" required :show-required-icon='false' v-model="email" regex="email" placeholder="请输入邮箱地址"></yd-input>
                </yd-cell-item>
                <yd-cell-item>
                    <yd-textarea slot="right" v-model="feedback" placeholder="请写下您的意见反馈内容" maxlength="200"></yd-textarea>
                </yd-cell-item>
            </yd-cell-group>
            <yd-button size="large" style="width:96%;margin:0 auto" @click.native="adds" type="danger">提交</yd-button>
        </div>
    </div>
</template>
<script>

export default {
    name: 'feedback',
    data() {
        return {
            ifTitle: '',
            ifMember: '',
            email: '',
            feedback: ''
        }
    },
    methods: {
        adds() {
            if (this.ifTitle == '') {
                this.$dialog.toast({
                    mes: '标题不可为空',
                    timeout: 600
                });
                return false;
            }
            if (this.ifMember == '') {
                this.$dialog.toast({
                    mes: '称呼不可为空',
                    timeout: 600
                });
                return false;
            }
            if (this.email == '') {
                this.$dialog.toast({
                    mes: '邮箱不可为空',
                    timeout: 600
                });
                return false;
            }
            let emailName = this.$refs.emailName;
            if (!emailName.valid) {
                let toastList = emailName.errorMsg;
                this.$dialog.toast({
                    mes: toastList,
                    timeout: 600
                });
                return false;
            }
            if (this.feedback == '') {
                this.$dialog.toast({
                    mes: '反馈内容不可为空',
                    timeout: 600
                });
                return false;
            }
            let msg = {
                ifTitle: this.ifTitle,
                ifMember: this.ifMember,
                ifMail: this.email,
                ifContent: this.feedback
            }
            this.$dialog.loading.open('正在提交');
            this.$httpAjax.post(this.CONSTANT.wapiBaseUrl + 'ideasFeedback/add', msg)
                .then((response) => {
                    if (response.data.status == 1) {
                        this.$dialog.toast({
                            mes: '提交成功',
                            timeout: 300
                        });
                    }
                    this.$router.go(-1);
                    this.$dialog.loading.close();
                }).catch((error) => {
                    this.$dialog.loading.close();
                });
        }
    }
}
</script>
<style  scoped>
.dangerBtn {
    width: 100%;
    margin: 0 auto;
}

#feedback .yd-textarea>textarea {
    height: 3.5rem!important;
}
</style>